﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;

namespace 自动关机Tool
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btn_30_Click(object sender, EventArgs e)
        {
            AutoShutDown(1800);
        }

        private void AutoShutDown(int time)
        {
            Process p = new Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;                //
            p.StartInfo.CreateNoWindow = true;                        //不显示控制台
            p.Start();

            if (time > 0)
            {
                string timer = string.Format("-s -t {0}", time);
                
                p.StandardInput.WriteLine(" shutdown -s -t " + time);
            }
            else
            {
                p.StandardInput.WriteLine(" shutdown -a ");
            }

        }
        
        private void btn_60_Click(object sender, EventArgs e)
        {
            AutoShutDown(3600);
        }

        private void btn_120_Click(object sender, EventArgs e)
        {
            AutoShutDown(7200);
        }

        private void btn_zidingyi_Click(object sender, EventArgs e)
        {
            try
            {
                int i = int.Parse(txt_Time.Text.Trim().ToString());
                i = i * 60;
                AutoShutDown(i);
            }
            catch
            {
                txt_Time.Clear();
                txt_Time.Focus();
                MessageBox.Show("在那儿输入一个整数，智障");
            }
        }

        private void btn_chexiao_Click(object sender, EventArgs e)
        {
            AutoShutDown(0);
        }
        
    }
}
